package vip.denglei.company.controller.app;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import vip.denglei.company.model.app.AppProduct;
import vip.denglei.company.service.app.AppProductService;
import vip.denglei.company.util.HttpResult;

import javax.annotation.Resource;

@RequestMapping(value = "/appProduct")
@RestController
@Slf4j
public class AppProductController {
    @Resource
    private AppProductService appProductService;

    @GetMapping("query/appProductPage/{pageNum}/{pageSize}")
    public HttpResult queryAppProductPageByUserId(@PathVariable Integer pageNum, @PathVariable Integer pageSize) {
        log.info("AppProductController queryAppProductPageByUserId 参数pageNum:{},pageSize:{}", pageNum, pageNum);
        Page<AppProduct> page = new Page(pageNum, pageSize);
        LambdaQueryWrapper<AppProduct> userAddressLambdaQueryWrapper = new LambdaQueryWrapper<>();
        userAddressLambdaQueryWrapper.eq(AppProduct::getDeleteFlag, 0);
        userAddressLambdaQueryWrapper.orderByAsc(AppProduct::getProSort);
        return HttpResult.success(appProductService.page(page, userAddressLambdaQueryWrapper));
    }

    /**
     * 通过商品id查询商品
     * @param proId
     * @return
     */
    @GetMapping("query/appProduct/{proId}")
    public HttpResult queryAppProductPageByUserId(@PathVariable(value = "proId") String proId) {
        log.info("AppProductController queryAppProductPageByUserId 参数proId:{}", proId);
        LambdaQueryWrapper<AppProduct> userAddressLambdaQueryWrapper = new LambdaQueryWrapper<>();
        userAddressLambdaQueryWrapper.eq(AppProduct::getProId, proId);
        userAddressLambdaQueryWrapper.eq(AppProduct::getDeleteFlag, 0);
        return HttpResult.success(appProductService.getOne(userAddressLambdaQueryWrapper));
    }


}
